package com.example.demo.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.demo.entity.Platform;
import com.example.demo.entity.PlatformPaper;
import com.example.demo.entity.Research;
import com.example.demo.entity.vo.ResearchVo;
import com.example.demo.mapper.ResearchMapper;
import com.example.demo.service.ResearchMemberService;
import com.example.demo.service.ResearchPatentService;
import com.example.demo.service.ResearchService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * @author lzc
 * @date 2021/11/10 15 47
 * discription
 */
@Slf4j
@Service
public class ResearchServiceImpl extends ServiceImpl<ResearchMapper, Research> implements ResearchService {

    @Autowired
    private ResearchMemberService researchMemberService;

    @Autowired
    private ResearchPatentService researchPatentService;


    @Override
    public List<ResearchVo> findByPlatformId(Integer platformId) {
        QueryWrapper<Research> queryWrapper = new QueryWrapper<Research>().
                eq(platformId != null, "platform_id", platformId);
        List<Research> list = super.list(queryWrapper);
        List<ResearchVo> researchVoList = new ArrayList<>();
        for (Research research : list) {
            researchVoList.add(getResearchVoByResearch(research));
        }

        return researchVoList;
    }

    private ResearchVo getResearchVoByResearch(Research research) {
        ResearchVo researchVo = new ResearchVo();
        researchVo.setResearch(research);
        researchVo.setMemberList(researchMemberService.findByResearchId(research.getId()));
        researchVo.setPatentList(researchPatentService.findByResearchId(research.getId()));
        return researchVo;
    }
}
